package com.onpositive.wiki3.db.impl;

import java.io.File;
import java.io.PrintStream;
import java.util.ArrayList;

import com.onpositive.wiki3.db.catmodel.Categories;
import com.onpositive.wiki3.db.catmodel.Category;
import com.onpositive.wiki3.db.catmodel.matches.classify.ByMatcher;
import com.onpositive.wiki3.db.catmodel.matches.classify.PluralCoreMatcher;
import com.onpositive.wiki3.db.catmodel.matches.classify.RelationConstants;
import com.onpositive.wiki3.db.catmodel.matches.classify.RelationStore;
import com.onpositive.wiki3.db.catmodel.matches.classify.YearMatcher;
import com.onpositive.wiki3.db.impl.CountingVocabalary.Pair;

public class Test3 {

	
	
	public static void main(String[] args) {
		final WikiDBImpl wikiDBImpl = new WikiDBImpl("C:/work/content");
		try {
			final Categories c = new Categories(wikiDBImpl, new File(
					"C:/work/content/n2.cats"), false);
			
			
			System.setProperty("wordnet.database.dir", "C:/work/wn/dict");
			c.removeAllContaining(wikiDBImpl, "_by_quality");
			c.removeAllContaining(wikiDBImpl, "_by_importance");
			c.removeAllContaining(wikiDBImpl, "wikipedia_books_");
			c.removeAllContaining(wikiDBImpl, "wikiproject");
			c.removeAllContaining(wikiDBImpl, "categories_by_type");
			c.fillLevels("contents", wikiDBImpl);
			final RelationStore ss=new RelationStore(wikiDBImpl);
			ByMatcher m = new ByMatcher(ss);
//			c.accept(m);
//			
//			
			//c.accept(new YearMatcher(ss, c));
			
			new PluralCoreMatcher(wikiDBImpl,c, ss).accept( c.get("buildings_and_structures_in_perry_county,_mississippi"));
			//c.accept(new PluralCoreMatcher(wikiDBImpl, c, ss));
			//m.close(c);
			Categories categories = ss.get(RelationConstants.IS_A);
			Categories categories2 = ss.get(RelationConstants.GARBAGE);
			System.out.println(categories.size()+categories2.size());
			System.out.println(c.size());
			ss.save();
			c.write(new File("C:/work/content/n7.cats"));
			PrintStream ps1=new PrintStream(wikiDBImpl.getPath()+"/all.txt");
			CountingVocabalary ccm=new CountingVocabalary();
			for (Category q:c){
				if (categories.get(q.id())==null&&categories2.get(q.id())==null){
					ps1.println(q.toString());
					String[] split = q.toString().split("_");
					System.out.println(q.toString());
					for (String s:split){
						ccm.add(s);
					}
				}
			}
			ArrayList<Pair> all = ccm.all();
			PrintStream ps=new PrintStream(wikiDBImpl.getPath()+"/fr.txt");
			for (Pair p:all){
				ps.println(p);
			}
		} catch (Exception e) {
			e.printStackTrace();
			// TODO: handle exception
		}
	}
}
